From f6eb2b3f8770ba0d9914b26343fee00a40b69a72 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 27 Jan 2013 22:07:52 +0000 Subject: [PATCH] Mechanically simplify the argument to localtime and gmtime in several formats to make operator overload easier to create for those. --- gpsbabel/cet_util.cc | 6 ++++-- gpsbabel/csv_util.cc | 11 +++++++---- gpsbabel/gpssim.cc | 4 +++- gpsbabel/magnav.cc | 9 +++++---- gpsbabel/nmea.cc | 3 ++- gpsbabel/pocketfms_bc.cc | 6 ++++-- gpsbabel/stmsdf.cc | 3 ++- gpsbabel/unicsv.cc | 8 +++++--- gpsbabel/xmlgeneric.cc | 5 ++--- 9 files changed, 34 insertions(+), 21 deletions(-) diff --git a/gpsbabel/cet_util.cc b/gpsbabel/cet_util.cc index b7721cef3..3bdb49a45 100644 --- a/gpsbabel/cet_util.cc +++ b/gpsbabel/cet_util.cc @@ -1045,8 +1045,10 @@ cet_convert_waypt(const waypoint* wpt) url_next->url = cet_convert_string(url_next->url); url_next->url_link_text = cet_convert_string(url_next->url_link_text); } - gc_data->placer = cet_convert_string(gc_data->placer); - gc_data->hint = cet_convert_string(gc_data->hint); + if (gc_data) { + gc_data->placer = cet_convert_string(gc_data->placer); + gc_data->hint = cet_convert_string(gc_data->hint); + } fs = wpt->fs; while (fs != NULL) { diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index ff439b9e5..9f856ebb9 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1224,8 +1224,10 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp, case XT_ISO_TIME_MS: wpt->creation_time = xml_parse_time(s, &wpt->microseconds); break; - case XT_NET_TIME: - dotnet_time_to_time_t(atof(s), &wpt->creation_time, &wpt->microseconds); + case XT_NET_TIME: { + time_t tt = wpt->creation_time; + dotnet_time_to_time_t(atof(s), &tt, &wpt->microseconds); + } break; case XT_GEOCACHE_LAST_FOUND: waypt_alloc_gc_data(wpt)->last_found = yyyymmdd_to_time(s); @@ -1939,8 +1941,9 @@ xcsv_waypt_pr(const waypoint* wpt) writebuff(buff, fmp->printfc, TIMET_TO_EXCEL(wpt->creation_time)); break; case XT_TIMET_TIME: - /* time as a time_t variable */ - writebuff(buff, fmp->printfc, wpt->creation_time); + /* time as a time_t variable */ { + time_t tt = wpt->creation_time; + writebuff(buff, fmp->printfc, tt); } break; case XT_TIMET_TIME_MS: { /* time as a time_t variable in milliseconds */ diff --git a/gpsbabel/gpssim.cc b/gpsbabel/gpssim.cc index 618463e7e..83482989d 100644 --- a/gpsbabel/gpssim.cc +++ b/gpsbabel/gpssim.cc @@ -124,9 +124,11 @@ gpssim_write_pt(const waypoint* wpt) int hms, ymd; struct tm* tm; - tm = gmtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = gmtime(&tt); hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; + snprintf(tbuf, sizeof(tbuf), ",%d,%d",ymd, hms); strcat(obuf, tbuf); } diff --git a/gpsbabel/magnav.cc b/gpsbabel/magnav.cc index 49a6a1e28..4ec0a6f1c 100644 --- a/gpsbabel/magnav.cc +++ b/gpsbabel/magnav.cc @@ -132,18 +132,19 @@ static void my_writewpt(const waypoint* wpt) { struct record* rec; - struct tm* tm; char* vdata; - time_t tm_t; const char* sn = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname; rec = (struct record*) xcalloc(sizeof(*rec)+56,1); + time_t tm_t; + struct tm* tm; tm = NULL; if (wpt->creation_time) { - tm = gmtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = gmtime(&tt); } if (!tm) { tm_t = current_time(); @@ -202,7 +203,7 @@ my_writewpt(const waypoint* wpt) static void data_write(void) { - static char* appinfo = + static const char* appinfo = "\0\x01" "User\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" diff --git a/gpsbabel/nmea.cc b/gpsbabel/nmea.cc index f27da4159..47ba567c3 100644 --- a/gpsbabel/nmea.cc +++ b/gpsbabel/nmea.cc @@ -1272,7 +1272,8 @@ nmea_trackpt_pr(const waypoint* wpt) lat = degrees2ddmm(wpt->latitude); lon = degrees2ddmm(wpt->longitude); - tm = gmtime(&wpt->creation_time); + time_t ct = wpt->creation_time; + tm = gmtime(&ct); if (tm) { hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; diff --git a/gpsbabel/pocketfms_bc.cc b/gpsbabel/pocketfms_bc.cc index e7f788492..4b9e7cc5d 100644 --- a/gpsbabel/pocketfms_bc.cc +++ b/gpsbabel/pocketfms_bc.cc @@ -132,9 +132,11 @@ pocketfms_waypt_disp(const waypoint *wpt) struct tm *tm; memset(&bc, 0, sizeof(bc)); - tm = localtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = localtime(&tt); if (wpt->creation_time) { - tm = gmtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = gmtime(&tt); } strcpy(bc.id, header_id); diff --git a/gpsbabel/stmsdf.cc b/gpsbabel/stmsdf.cc index 3e69a41ab..b2e548d5e 100644 --- a/gpsbabel/stmsdf.cc +++ b/gpsbabel/stmsdf.cc @@ -585,7 +585,8 @@ track_disp_wpt_cb(const waypoint *wpt) track_points++; all_track_points++; - tm = *localtime(&wpt->creation_time); + time_t ct = wpt->creation_time; + tm = *localtime(&ct); strftime(tbuf, sizeof(tbuf), "%d.%m.%Y,%H:%M.%S", &tm); calculate(wpt, &dist, &speed, &course, NULL, NULL); diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 0b89aaf6a..42d8d831f 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -1641,7 +1641,7 @@ unicsv_waypt_disp_cb(const waypoint *wpt) } } if FIELD_USED(fld_fix) { - char *fix; + const char *fix; switch (wpt->fix) { case fix_none: fix = "none"; @@ -1726,7 +1726,8 @@ unicsv_waypt_disp_cb(const waypoint *wpt) time += atoi(opt_utc) * SECONDS_PER_HOUR; tm = *gmtime(&time); } else { - tm = *localtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = *localtime(&tt); } tm.tm_year += 1900; tm.tm_mon += 1; @@ -1746,7 +1747,8 @@ unicsv_waypt_disp_cb(const waypoint *wpt) time += atoi(opt_utc) * SECONDS_PER_HOUR; tm = *gmtime(&time); } else { - tm = *localtime(&wpt->creation_time); + const time_t tt = wpt->creation_time; + tm = *localtime(&tt); } snprintf(buf, sizeof(buf), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec); diff --git a/gpsbabel/xmlgeneric.cc b/gpsbabel/xmlgeneric.cc index 53c85fdfa..70703097f 100644 --- a/gpsbabel/xmlgeneric.cc +++ b/gpsbabel/xmlgeneric.cc @@ -105,7 +105,7 @@ void xml_fill_in_time(char *time_string, const time_t timep, int microseconds, int long_or_short) { struct tm *tm = gmtime(&timep); - char *format; + const char *format; int n; if (!tm) { @@ -145,7 +145,6 @@ xml_write_time(gbfile *ofd, const time_t timep, int microseconds, const char *el elname ); } - } /*********************************************************************** @@ -301,7 +300,7 @@ void xml_readstring(char *str) XML_ParserFree(psr); } -void xml_readprefixstring(char *str) +void xml_readprefixstring(const char *str) { int len = strlen(str); if (!XML_Parse(psr, str, len, 0)) { -- 2.30.2